package com.onlinevideo.dao.impl;

import com.onlinevideo.dao.BaseDao;
import com.onlinevideo.dao.FavoritesVideoDao;
import com.onlinevideo.entity.FavoritesVideo;

import java.util.List;

public class FavoritesVideoDaoImpl  extends BaseDao implements FavoritesVideoDao {

    @Override
    public int insert(FavoritesVideo favoritesVideo) {
        String sql ="INSERT INTO `T_favorites_video` (`favorites_id`,`video_id`) VALUES (?,?)";
        return super.update(sql,favoritesVideo.getFavoritesId(),favoritesVideo.getVideoId());
    }

    @Override
    public int delete(Long id) {
        String sql = "DELETE FROM `T_favorites_video` WHERE `id`=?";
        return super.update(sql,id);
    }

    @Override
    public int update(FavoritesVideo favoritesVideo) {
        String sql ="UPDATE `T_favorites_video` SET `favorites_id`=?,`video_id`=? WHERE `id`=?";
        return super.update(sql,favoritesVideo.getFavoritesId(),favoritesVideo.getVideoId(),favoritesVideo.getId());
    }

    @Override
    public FavoritesVideo queryById(Long id) {
        String sql ="SELECT `id`,`favorites_id` AS `favoritesId`,`video_id` AS `videoId` FROM `T_favorites_video` WHERE 1=1 AND `id`=? ";
        return super.queryForOne(FavoritesVideo.class,sql,id);
    }

    @Override
    public List<FavoritesVideo> queryAll() {
        String sql ="SELECT `id`,`favorites_id` AS `favoritesId`,`video_id` AS `videoId` FROM `T_favorites_video` WHERE 1=1 ";
        return super.queryForList(FavoritesVideo.class,sql);
    }

    @Override
    public List<FavoritesVideo> queryByFavorites(Long favoritesId) {
        String sql ="SELECT `id`,`favorites_id` AS `favoritesId`,`video_id` AS `videoId` FROM `T_favorites_video` WHERE 1=1 AND `favorites_id`=?";
        return super.queryForList(FavoritesVideo.class,sql,favoritesId);
    }

    @Override
    public List<FavoritesVideo> queryByFavorAndVideo(Long favoritesId, Long videoId) {
        String sql ="SELECT `id`,`favorites_id` AS `favoritesId`,`video_id` AS `videoId` FROM `T_favorites_video` WHERE 1=1 AND `favorites_id`=? AND `video_id`=?";
        return super.queryForList(FavoritesVideo.class,sql,favoritesId,videoId);
    }

    @Override
    public int deleteByVideoId(Long videoId) {
        String sql = "DELETE FROM `T_favorites_video` WHERE `video_id`=?";
        return super.update(sql,videoId);
    }
}
